package com.h.mybatis.service;

import com.h.mybatis.mapper.UserInfoMapper;
import com.h.mybatis.mapper.UserInfoMapperXML;
import com.h.mybatis.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private UserInfoMapperXML userInfoMapperXML;

    public List<UserInfo> getAllUser() {
        return userInfoMapper.selectAll();
    }

    public UserInfo getAllById(Integer id) {
        return userInfoMapper.selectAllById2(id);
    }

    public List<UserInfo> getXMLAllById(Integer id) {
        return userInfoMapperXML.selectAllById(id);
    }

    public UserInfo queryUserByUserNameAndPassword(String username, String password) {
        List<UserInfo> userInfos = userInfoMapper.selectNameAndPassword7(username, password);
        if(userInfos != null && userInfos.size() >= 1) {
            // 这里的size() <=1 就可能不会出现SQL注入问题
            return userInfos.get(0);
        }
        return null;
    }

}
